﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UniMana.Utils.Controls;
using UniMana.Utils.Configs;
using UniMana.Data;

namespace UniMana.Data
{
    public class Personnel_AttendanceInfo
    {
        #region /*Không thay đổi*/
            public bds m_bds = new bds();
            public void Save()
            {
                m_data.m_DCSave.SubmitChanges();
            }
            public void Delete()
            {
                m_bds.DeleteCurrent();
            }
            #endregion /*Không thay đổi*/

            private DBMain m_data = new DBMain();

            #region [Properties - Thuộc tính]
            public Personnel_Attendance Properties
            {
                get { return m_bds.Current as Personnel_Attendance; }
            }
            #endregion

            public Personnel_AttendanceInfo(int _Year, int _Month, int _deptKey)
            {
                var IQuery = m_data.m_DCSave.Personnel_Attendances.Where(p => p.Year == _Year && p.Month == _Month && p.Catalogue_DepartmentKey == _deptKey);
                m_bds.DataSource = IQuery;
                var Row = IQuery.FirstOrDefault();
                if (Row == null)
                {
                    Row = new Personnel_Attendance();
                    Row.Personnel_AttendanceKey = -1;
                    Row.Year = _Year;
                    Row.Month = _Month;
                    Row.Catalogue_DepartmentKey = _deptKey;
                    m_bds.Add(Row);
                }
            }
    }
}
